<!doctype html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- 必须的 meta 标签 -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap 的 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../../static/css/main.css" th:href="@{/static/css/main.css}">
    <title>订单管理</title>
</head>
<body>

<div class="row-2">
    <nav class="navbar navbar-expand-lg navbar-light bg-light" style="height: 80px">
        <a class="topA navbar-brand" th:href="@{/admin/user}" href="#">用户管理</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02"
                aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
            <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
                <li class="nav-item active">
                    <a class="topA nav-link" th:href="@{/book/book}" href="#">图书信息管理</a>
                </li>
                <li class="nav-item">
                    <a class="topA nav-link" th:href="@{/order/selectAllOrder}" href="#">订单管理</a>
                </li>
            </ul>
            <span th:text="${message}" style="margin-right: 450px;color: red"></span>
        </div>
    </nav>
</div>


<div class="row-10">
    <div id="tab" th:fragment="tab">
        <table class="table">
            <thead>
            <tr>
                <th scope="col">序号</th>
                <th scope="col">购买人</th>
                <th scope="col">联系方式</th>
                <th scope="col">家庭住址</th>
                <th scope="col">付款金额</th>
                <th scope="col">下单时间</th>
                <th scope="col">操作</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="order:${orders}">
                <th th:text="${order.id}" scope="row">1</th>
                <td th:text="${order.name}">Mark</td>
                <td th:text="${order.phone}">12345</td>
                <td th:text="${order.address}">地球笔记村101</td>
                <td th:text="${order.payMoney}">129</td>
                <td th:text="${order.createTime}">2022-10-11</td>
                <td>
                    <button type="button" th:onclick="|motai(${order.id})|" class="upd btn btn-dark">修改</button>
                    <!--模态窗口-->
                    <div id="myMo" class="modal" tabindex="-1">
                        <div class="container">
                            <div class="modal-content">
                                <div class="modal-body">
                                    购买人：<input type="text" id="name" name="name"><br>
                                    电话号码：<input type="text" id="phone" name="phone"><br>
                                    家庭住址：<input type="text" id="address" name="address"><br>
                                    付款金额：<input type="text" id="payMoney" name="payMoney"><br>
                                    <button onclick="rush()" type="submit">提交</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>


<!-- JavaScript 文件是可选的。从以下两种建议中选择一个即可！ -->

<!-- 选项 1：jQuery 和 Bootstrap 集成包（集成了 Popper） -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>

<script>
    let id;
    function motai(i) {
        id = i
        $('#myMo').modal('show');
    }

    function rush() {
        var name = $("#name").val();
        var phone = $("#phone").val();
        var address = $("#address").val();
        var payMoney = $("#payMoney").val();

        $.ajax({
            url:'/bookCity/order/updateOrder',
            data:{
                id:id,
                name:name,
                phone:phone,
                address:address,
                payMoney:payMoney,
            },
            success:function (data) {
                $("#tab").html(data);
            }
        })
        $("#myMo").modal('hide');
    }
</script>

</body>
</html>